/*
 * @Author: gavin
 * @Date:   2017-12-19 21:58:43
 * @Last Modified by:   gavin
 * @Last Modified time: 2017-12-24 23:03:38
 */
import React from 'react';
import { hydrate, render } from 'react-dom';
import { BrowserRouter as Router } from 'react-router-dom';
import { Provider } from 'mobx-react';

import stores,{init} from '@/store/webStore';
import App from '@/shared_web';

import { AppContainer } from 'react-hot-loader';

const rootElement = document.getElementById('root');
// init();
let Code = (Component) =>(
	<AppContainer>
		<Provider {...stores}>
			<Router><Component /></Router>
		</Provider>
	</AppContainer>
);
let rending = (Component) => {
	if (rootElement.hasChildNodes()) {
		hydrate(Code(Component), rootElement);
	} else {
		render(Code(Component), rootElement);
	}
};

rending(App);

if (module.hot) {
	module.hot.accept('../shared_web', (err) => {
		if (err) {
			console.log(err);
		}
		// ReactDOM.unmountComponentAtNode(rootElement);
		rending(App);
	});
}
